const app = getApp();
Page({
  data: {
    showModalStatus: false,
    contacts: [],
    searchItem: ''
  },
  onShow: function () {
    const _this = this;
    wx.getStorage({
      key: 'contact',
      success: function (res) {
        console.log(res.data)
        console.log('----------------------------')
        _this.setData({
          searchItem: res.data
        })
      }
    })
    this.getContacts();
    console.log(_this.data.searchItem)
    if (!_this.data.searchItem) {
      _this.setData({
        searchItem: ''
      })
    }
  },
  //其他用户信息
  toNext: function (e) {
    console.log(e.detail.value.bankId);
    const _this = this;
    wx.request({
      url: app.globalData.path + 'services/app/applets/GetOtherUserInfo',
      data: {
        phoneNumOrIdentityCard: e.detail.value.bankId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization': 'Bearer ' + app.globalData.authorization
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.success) {
          _this.tojump(e.detail.value.bankId);
        } else {
          _this.setData({
            showModalStatus: true
          })
          // wx.showToast({
          //   title: res.data.error.message,
          //   icon: 'none',
          //   duration: 2000
          // })
        }
      }
    })
  },
  // 关闭弹框
  closemodal: function () {
    this.setData({
      showModalStatus: false
    })
  },
  // 跳转
  tojump: function (id) {
    wx.navigateTo({
      url: '../othernext/othernext?bankId=' + id + '&from=withdraw'
    })
  },
  // 分享
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '薪金宝',
      path: 'pages/login/login'
    }
  },
  aa: function () {
    this.setData({
      showModalStatus: true
    })
  },
  // 最近转账
  getContacts() {
    const _this = this;
    wx.request({
      url: app.globalData.path + 'services/app/applets/GetRecentContacts',
      data: {
        type: 1
      },
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization': 'Bearer ' + app.globalData.authorization
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.success) {
          _this.setData({
            contacts: res.data.result.items
          })
        } else {
          wx.showToast({
            title: res.data.error.message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 点击事件
  getContact(e) {
    const _this = this;
    var idx = e.currentTarget.id;
    _this.setData({
      searchItem: _this.data.contacts[idx].phoneNumber
    })
  },
  // 联系人
  toContact() {
    wx.navigateTo({
      url: '../contacts/contacts',
    })
  }
})